﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntityModel;
using BusinessLayer;
using System.Data.Linq;

namespace PL___Web_Application
{
    public partial class Image : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string type = Request.QueryString["type"];
              
                
                if (type == "car")
                {
                    string car_reg = Request.QueryString["id"];
                    BL controller = new BL();
                    Car car = controller.getCar(car_reg);
                    Byte[] aux = (car.Vehicle.v_image).ToArray();
                    Response.ContentType = "image/jpg";
                    Response.BinaryWrite(aux);
                }
                else {
                    string truck_reg = Request.QueryString["id"];
                    BL controller = new BL();
                    Truck truck = controller.getTruck(truck_reg);
                    Byte[] aux = (truck.Vehicle.v_image).ToArray();
                    Response.ContentType = "image/jpg";
                    Response.BinaryWrite(aux);
                }
            }
            catch {
                Response.ContentType = "image/jpg";
                Response.WriteFile("grafics/unknown.jpeg");
            }
        }
    }
}